package webcert.ch03.ex0303;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

//@WebServlet(name = "Receiver", urlPatterns = "/Receiver/*")
public class Receiver extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();

        out.write("Parameters:");

        Enumeration<String> parameters = request.getParameterNames();
        while (parameters.hasMoreElements()) {
            String parameterName = parameters.nextElement();
            out.write("\nParamter: " + parameterName);
            for (String paramterValue : request.getParameterValues(parameterName)) {
                out.write(paramterValue + " ");
            }
        }

        out.write("Attributes:");

        Enumeration<String> attributes = request.getAttributeNames();
        while (attributes.hasMoreElements()) {
            String attributeName = attributes.nextElement();
            out.write("\nAttribute: " + request.getAttribute(attributeName));

        }

    }
}
